<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Graph demo - javascript data</title>

    <style type="text/css">
        body {font: 10pt arial;}
    </style>

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript" src="../graph.js"></script>
    <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../graph.css">

    <script type="text/javascript">
        var data;
        var graph;
        google.load("visualization", "1");

        // Set callback to run when API is loaded
        google.setOnLoadCallback(drawVisualization);

        function functionA(x) {
            return -Math.sin(x / 10) * Math.cos(x / 5) * 50;
        }

        function functionB(x) {
            return Math.sin(x/5) *45 + Math.cos(x / 10) * 75;
        }

        // Called when the Visualization API is loaded.
        function drawVisualization() {
            // Create and populate a data table.
            var dataset, datapoint, d, i;

            // create data for graph1
            dataset = [];
            d = new Date(2010, 9, 28, 20, 0, 0);
            for (i = 0; i < 50; i++) {
                datapoint = {
                    "date": new Date(d),
                    "value" : (functionA(i) / 200)
                };
                dataset.push(datapoint);
                d.setHours(d.getHours() + 5);
            }
            var graph1 = {"label": "Dataset A", "data" : dataset};

            // create data for graph2
            dataset = [];
            d = new Date(2010, 9, 30, 16, 0, 0);
            for (i = 0; i < 30; i++) {
                datapoint = {
                    "date": new Date(d),
                    "value" : (functionB(i) / 200)
                };
                dataset.push(datapoint);
                d.setHours(d.getHours() + 5);
            }
            var graph2 = {"label": "Dataset B", "data" : dataset};

            // put all datasets in one array
            data = [graph1, graph2];

            // specify options
            var options = {width:  "100%",
                height: "350px",
                lines: [
                    {color: "#2B7CE9", style: "dot", radius: 1.5},
                    {color: "#97C2FC", width: 2}
                ],
                tooltip: function (point) {
                    return data[point.line].label + '<br>'  +
                            point.value.toPrecision(6);
                }
            };

            // Instantiate our graph object.
            graph = new links.Graph(document.getElementById('mygraph'));

            // Draw our graph with the created data and options
            graph.draw(data, options);
        }
    </script>
</head>

<body>
<div id="mygraph"></div>
</body>
</html>
